﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.SoldierArchives.Model;
using Yipusoft.SoldierArchives.BLL;
using Yipusoft.TranslateApprove.BLL;
using Yipusoft.TranslateApprove.Model;

public partial class Police_TranslateProcess_ProcessList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ListPageContral1.SetFirstPage();
            bindGV(0);
        }
    }

    protected void ListPageContral1_PageSizeChange(int pageSize, int PageIndex)
    {
        bindGV(PageIndex);
    }

    void bindGV(int pageIndex)
    {
        string where = "";
        List<TranslateInfo> list = Translate.GetListWithNoComplete(ListPageContral1.PageSize, pageIndex);
        ListPageContral1.ItemCount = Translate.NoCompleteCount();
        UserGrid.DataSource = list;
        UserGrid.DataBind();
    }
    protected void UserGrid_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label ID = (Label)e.Row.FindControl("ID");
            ID.Text = ((ListPageContral1.CurrentPageIndex * ListPageContral1.PageSize) + (e.Row.RowIndex + 1)).ToString();
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");

            LinkButton op = e.Row.FindControl("op") as LinkButton;

            TranslateInfo Info = Translate.GetDetail(new Guid(UserGrid.DataKeys[e.Row.RowIndex].Value.ToString()));
            //查看
            TranslateLogInfo log = TranslateLogs.GetLastDetail(Info.ID);
            if (log != null)
            {

                Label state = e.Row.FindControl("state") as Label;
                TranslateProcessInfo PInfo = TranslateProcess.GetDetail(log.PID);

                state.Text = PInfo.ProcessName + "完成";

                if (TranslateProcess.GetNextDetail(log.PID) != null)
                {
                    if (TranslateProcess.GetDetail(log.PID).ProcessName == "请示")
                    {
                        Guid AID = log.DID;
                        string where = "Fid='" + AID + "'";
                        List<SetupLogInfo> list = SetupLog.GetList(where);
                        if (list.Count > 0)
                        {
                            state.Text = SetupLog.GetCurrentState(log.DID);
                            if (state.Text == "审批通过")
                            {
                                state.ForeColor = System.Drawing.Color.Red;
                                //如果是调入
                                if (Info.TID == 1)
                                {
                                    
                                    op.Text = "开商调函";
                                    op.PostBackUrl = "../TranslateDocument/TransferTreatNew.aspx?Fid=" + UserGrid.DataKeys[e.Row.RowIndex].Value.ToString();
                                }
                                else
                                {
                                    op.Text = "开调令";
                                    op.PostBackUrl = "../TranslateDocument/TranslateOrderNew.aspx?Fid=" + UserGrid.DataKeys[e.Row.RowIndex].Value.ToString();
                                }
                            }
                        }
                    }
                    if (TranslateProcess.GetNextDetail(log.PID).ProcessName == "上传对方介绍信")
                    {
                        state.Text = "等待士兵报到";
                        op.Text = "士兵报到";
                        op.PostBackUrl = "../TranslateDocument/IntroduceLetterNew.aspx?Fid=" + UserGrid.DataKeys[e.Row.RowIndex].Value.ToString();
                         
                    }

                }
                else
                {
                    state.ForeColor = System.Drawing.Color.Red;
                }

            }
            else
            {
                op.Text = "请示";
                op.PostBackUrl = "../TranslateApprove/AppalyNew.aspx?Fid=" + UserGrid.DataKeys[e.Row.RowIndex].Value.ToString();
            }
        }
    }

    protected void UserGrid_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }

    public string getType(int TID)
    {

        switch (TID)
        {
            case 1:
                return "调入";
            case 2:
                return "调出";
            case 3:
                return "内部调动";
            default:
                return "";
        }

    }

}
